package com.hl233.framework.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.hl233.framework.config.DruidProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.mongodb.core.mapping.TextScore;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author 张振强15065206763
 * @create 2024-09-06
 */
@Component
public class DruidUtil {
    //声明连接池对象
    private static DruidDataSource ds;
    static {
        Properties properties =new Properties();
        InputStream is=DruidUtil.class.getResourceAsStream("/database.properties");
        try {
            properties.load(is);
            //创建连接池
            ds=(DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch ( Exception e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection() {
        try {
            return ds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
